package com.xunfei.zhm.car

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.amap.api.maps2d.AMap
import com.amap.api.maps2d.CameraUpdateFactory
import com.amap.api.maps2d.MapView
import com.amap.api.maps2d.model.LatLng
import com.amap.api.maps2d.model.MarkerOptions

class MainActivity : AppCompatActivity() {

    private lateinit var mapView: MapView
    private lateinit var aMap: AMap


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        mapView = findViewById(R.id.mapView)
        mapView.onCreate(savedInstanceState)

        aMap = mapView.map

        // 设置吉利学院的经纬度
        val geelyUniversity = LatLng(30.487792,  104.428457)

        // 添加标记
        val markerOptions = MarkerOptions()
            .position(geelyUniversity)
            .title("吉利学院")
            .snippet("四川省简阳市")
            .draggable(false)

        aMap.addMarker(markerOptions)

        // 移动地图视角到吉利学院，缩放级别设为 15（城市级别）
        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(geelyUniversity, 15f))
    }

    override fun onStart() {
        super.onStart()
    }

    override fun onPause() {
        super.onPause()
        mapView.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        mapView.onDestroy()
    }

    override fun onResume() {
        super.onResume()
        mapView.onResume()
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        mapView.onSaveInstanceState(outState)
    }
}